package instant.enums.test.validator;

import com.ilikesoup.instant.ValidationUtils;
import com.ilikesoup.instant.enums.basic.CodeEnum;
import com.ilikesoup.instant.enums.validation.EnumCode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import javax.validation.ValidationException;

public class EnumCodeValidatorTestCase {

    @Test
    public void testValidator() {
        Vo vo = new Vo(1);
        ValidationUtils.validateParams(vo);
    }

    @Test
    public void testValidatorThrow() {
        Vo vo = new Vo(2);
        Assertions.assertThrows(ValidationException.class, () -> ValidationUtils.validateParams(vo));
    }

    public static class Vo {
        @EnumCode(Status.class)
        private Integer status;

        public Vo(Integer status) {
            this.status = status;
        }

        public Integer getStatus() {
            return status;
        }

        public void setStatus(Integer status) {
            this.status = status;
        }
    }

    enum Status implements CodeEnum<Integer> {
        ENABLED(0),
        DISABLED(1),

        ;

        private final Integer code;

        Status(Integer code) {
            this.code = code;
        }

        @Override
        public Integer getCode() {
            return code;
        }

    }

}
